<?php

namespace App\Admin\Support;


use App\Models\OrderGoods;
use Dcat\Admin\Support\LazyRenderable;
use Dcat\Admin\Widgets\Table;

class OrderGoodsInfo extends LazyRenderable
{
    public function render()
    {
        // 获取ID
        $order_id = $this->key;

        $data = OrderGoods::with(['goodsInfo' => function ($query) {
            $query->select('goods_id', 'goods_name', 'goods_now_price');
        }])->where('order_id', $order_id)->get()->toArray();

        $goodsData = array_column($data, 'goods_info');
        $info = [];
        foreach ($goodsData as $k => $v) {
            $info[$k]['goods_id'] = $v[0]['goods_id'];
            $info[$k]['goods_name'] = $v[0]['goods_name'];
            $info[$k]['goods_now_price'] = $v[0]['goods_now_price'];
        }
        $titles = [
            '商品id',
            '商品名字',
            '商品价格'
        ];
        return Table::make($titles, $info);
    }
}
